A portion of the disclosure of this patent document contains material that is subject to copyright protection. The copyright owner has no objection to the facsimile reproduction by anyone of the patent document or the patent disclosure as it appears in the United States Patent and Trademark Office patent file or records, but otherwise reserves all copyright rights whatsoever.
1. Field of the Invention
The present invention is directed to computer systems, and more particularly, to methods, apparatus, and computer program products for persisting objects of an object-oriented environment in a relational database.
2. Description of the Prior Art
Relational databases represent one of the greatest advances in database technology. The feature that sets a relational database apart from earlier database technologies is the ability to separate the structure of the database from how the data is accessed. In earlier technologies, the structure of the data in a database and how it is accessed were tightly linked. This meant that if a programmer wanted to access the data from a different perspective, it could be very difficult. Relational databases introduce a data definition language to describe the structure of the data, and a separate data manipulation language to access the data. This allows programmers to access the data independently of how the data is actually structured.
Relational databases gain their flexibility from the fact that their data resides in tables that are largely independent of each other. Data can be added, deleted, or changed in one table without affecting the data in another table, provided the first table is not a parent of the other table. A table is a two-dimensional array of rows and columns. Every column in a database table embodies a single attribute of the table, and a column has the same meaning in every row of the table. For example, a table may contain the names, addresses, and phone numbers of all of the employees of a company. Each row of the table, also commonly referred to a record, holds the data for a single employee. Each column holds a single attribute, such as employee ID, employee name, street, city, state, postal code, or telephone number.
The structure of an entire database is its schema. The schema is sometimes also referred to as the conceptual view or the complete logical view of the database. The schema is metadata and, as such, is a part of the database. The metadata itself, which describes the structure of the database, is stored in tables similar to the tables described above used to store data. A schema contains information that identifies the tables that have been created to store data.
The data definition language of a relational database is used to create, change, or destroy the basic elements of a relational database, such as its schema and its tables. The data manipulation language of a relational database is used to operate on the data stored in the database, e.g., to insert, update, delete, or select data in the database.
Structured query language (SQL) is an ANSI standard language that has been specifically designed for the creation and maintenance of relational databases. SQL includes both data definition language commands and data manipulation language commands. For example, the data definition language of SQL includes a CREATE TABLE command that is used to create a table in the relational database. Within the command, the name and data type for each column of the table are specified. An ALTER TABLE command is provided for changing the table by, for example, adding, changing, or deleting a column in the table. The data manipulation language of SQL includes commands such as INSERT, UPDATE, DELETE, and SELECT that allow you to add, change, delete, and retrieve data in the rows (i.e., records) of a table.
Despite the significant advance that relational databases represent, there are still some issues with relational databases. For example, with a relational database, the structure of the database (schema) still has to be manually described, both initially and when changes are needed. Also, in a large database structure that can support diverse environments, a particular user might only use a small portion of the database, i.e., the portion relevant to the users environment, leaving much of the database structure unnecessary for that environment. Finally, relational databases are difficult to use in an object-oriented environment in which it is desired to store (i.e., persist) objects in a relational database.
Accordingly, there is a need for new methods, apparatus, and computer program products that improve the ability to persist objects of an object-oriented environment in a relational database. The present invention satisfies this need.
The present invention is directed to a method, apparatus, and computer program product for enabling objects of an object-oriented environment to be persisted in a relational database. In accordance with the present invention, an object to be persisted first stores its attributes in a property bag. A determination is then made whether the schema of the relational database supports the storage of objects of the class of the object to be persisted. If not, the relational database is dynamically reconfigured using commands of a data definition language of the relational database so that the schema supports the storage of objects of that class. This may include the creation of a new table for that class of objects or the modification of an existing table to accommodate new or different attributes of that class. Once any necessary modifications to the database schema have been made, commands of a data manipulation language of the relational database are generated to store in the appropriate table the attributes from the property bag of the object to be persisted.
Additional features and advantages of the present invention will become evident hereinafter.